package com.toycloud.common.excel.converter;

import com.alibaba.excel.converters.Converter;

import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.alibaba.excel.metadata.data.WriteCellData;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

public class DateListConverter implements Converter<List<Date>> {



    @Override
    public WriteCellData<?> convertToExcelData(List<Date> value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
        if (value == null || value.isEmpty()) {
            return new WriteCellData<>("");
        }
        // 将 List<Date> 转换为字符串，使用逗号分隔
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String formattedDates = value.stream()
                .map(dateFormat::format)
                .collect(Collectors.joining(", "));

        return new WriteCellData<>(formattedDates);
    }
}
